#
# Licensed to Dagda under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Dagda licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

import unittest
from analysis.static.av.malware_extractor import _parse_raw_output


# -- Test suite

class MalwareExtractorTestSuite(unittest.TestCase):

    def test_parse_raw_output(self):
        output = _parse_raw_output(mock_clamav_raw_output, '/tmp/tmpr_kmupom')
        self.assertEqual(len(output), 3)
        self.assertEqual(output[0]['file'], '/tmp/test/removal-tool.exe')
        self.assertEqual(output[0]['malware'], 'Worm.Sober')
        self.assertEqual(output[1]['file'], '/tmp/test/error.hta')
        self.assertEqual(output[1]['malware'], 'VBS.Inor.D')
        self.assertEqual(output[2]['file'], '/tmp/test/error1.hta')
        self.assertEqual(output[2]['malware'], 'VBS.Inor.D')


# -- Mock Constants

mock_clamav_raw_output = '''/tmp/test/removal-tool.exe: Worm.Sober FOUND
/tmp/test/md5.o: OK
/tmp/test/blob.c: OK
/tmp/test/message.c: OK
/tmp/test/error.hta: VBS.Inor.D FOUND
/tmp/tmpr_kmupom/tmp/test/error1.hta: VBS.Inor.D FOUND'''


if __name__ == '__main__':
    unittest.main()
